Skip to content

Conversation

@dreamfliper
Copy link
Owner

@dreamfliper dreamfliper commented May 29, 2025

User description

This change replaces the outdated simplecc library with the more modern and actively maintained opencc-rs (version 0.3.0) for Traditional/Simplified Chinese text conversion.

Reasons for the change:

  • simplecc was last updated in 2019 and used outdated OpenCC dictionaries.
  • opencc-rs is actively maintained and uses a much newer version of the OpenCC C++ library (v1.1.7 or v1.1.8 via opencc-sys), providing more accurate and up-to-date conversion dictionaries.

Changes made:

  • Removed simplecc dependency from src-tauri/Cargo.toml.
  • Added opencc-rs = "0.3.0" dependency to src-tauri/Cargo.toml. (Note: v0.3.0 was used over v0.4.9 due to Rust edition compatibility with the current project setup. This version still provides OpenCC dictionaries from 2024).
  • Updated src-tauri/src/main.rs to use the opencc-rs API for the opencc Tauri command, including error handling for conversion failures.

The backend now compiles successfully with these changes, and the Tauri application can be started in development mode for manual testing of the conversion functionality.


PR Type

Enhancement


Description

  • Replaced simplecc with opencc-rs for Chinese text conversion

  • Updated Rust backend code to use opencc-rs API and error handling

  • Removed simplecc dependency and added opencc-rs in Cargo.toml

  • Updated project version in package.json


Changes walkthrough 📝

Relevant files
Enhancement
main.rs
Migrate backend Chinese conversion to opencc-rs with improved error
handling

src-tauri/src/main.rs

  • Switched from simplecc to opencc-rs for text conversion
  • Updated the opencc command to use new API and error handling
  • Adjusted mode mapping to match new library's configuration
  • +16/-8   
    Dependencies
    Cargo.toml
    Update dependencies: remove simplecc, add opencc-rs           

    src-tauri/Cargo.toml

  • Removed simplecc dependency and related configuration
  • Added opencc-rs = "0.3.0" as a new dependency
  • +1/-5     
    Configuration changes
    package.json
    Update project version in package.json                                     

    package.json

    • Updated project version from 2 to 0.1.0
    +1/-1     

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • This change replaces the outdated `simplecc` library with the more
    modern and actively maintained `opencc-rs` (version 0.3.0) for
    Traditional/Simplified Chinese text conversion.
    
    Reasons for the change:
    - `simplecc` was last updated in 2019 and used outdated OpenCC dictionaries.
    - `opencc-rs` is actively maintained and uses a much newer version of the
      OpenCC C++ library (v1.1.7 or v1.1.8 via opencc-sys), providing more
      accurate and up-to-date conversion dictionaries.
    
    Changes made:
    - Removed `simplecc` dependency from `src-tauri/Cargo.toml`.
    - Added `opencc-rs = "0.3.0"` dependency to `src-tauri/Cargo.toml`.
      (Note: v0.3.0 was used over v0.4.9 due to Rust edition compatibility
      with the current project setup. This version still provides OpenCC
      dictionaries from 2024).
    - Updated `src-tauri/src/main.rs` to use the `opencc-rs` API for the
      `opencc` Tauri command, including error handling for conversion failures.
    
    The backend now compiles successfully with these changes, and the Tauri
    application can be started in development mode for manual testing of the
    conversion functionality.
    @qodo-code-review
    Copy link

    Qodo Merge was enabled for this repository. To continue using it, please link your Git account with your Qodo account here.

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Error Handling

    The error messages returned when conversion fails are exposed directly to the user interface. Consider whether these detailed error messages are appropriate for end users or if they should be logged instead with a more user-friendly message returned.

        Err(e) => return format!("Failed to create OpenCC instance: {}", e),
    };
    
    match converter.convert(&input) {
        Ok(s) => s,
        Err(e) => format!("Failed to convert string: {}", e),
    }
    Mode Mapping

    The comment on line 21 indicates that TW2S is being used to align with simplecc's T2S default. Verify that this mapping is functionally equivalent and produces the expected conversion results.

    let dict_config = match mode.as_str() {
        "s2twp" => Config::S2TWP,
        "s2tw" => Config::S2TW,
        "tw2s" | "tw2sp" => Config::TW2S, // Using TW2S to align with simplecc's T2S default
        _ => Config::S2TWP, // Default
    };

    @qodo-code-review
    Copy link

    Qodo Merge was enabled for this repository. To continue using it, please link your Git account with your Qodo account here.

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Return Result type

    Change the function signature to return a Result type to properly handle errors
    that may occur during conversion. This allows the Tauri runtime to handle errors
    appropriately.

    src-tauri/src/main.rs [16-17]

     #[tauri::command]
    -fn opencc(input: String, mode: String) -> String {
    +fn opencc(input: String, mode: String) -> Result<String, String> {
    • Apply / Chat
    Suggestion importance[1-10]: 6

    __

    Why: This is a valid improvement that would enable proper error handling in the Tauri command. While not critical since the current implementation works, returning Result types is better practice for error propagation.

    Low
    • More

    @qodo-code-review
    Copy link

    qodo-code-review bot commented May 29, 2025

    CI Feedback 🧐

    (Feedback updated until commit 1eeb1ac)

    A test triggered by this PR failed. Here is an AI-generated analysis of the failure:

    Action: build-tauri (ubuntu-latest)

    Failed stage: install app dependencies and build it [❌]

    Failure summary:

    The action failed because the build process couldn't find the required system library libsoup-2.4
    which is needed by the soup2-sys crate. The error message indicates:

  • Package libsoup-2.4 was not found in the pkg-config search path
  • The error occurred during the Rust compilation process (lines 1732-1737)
  • The build failed with exit code 1 (line 1742)

    This is a dependency issue where a required system library is missing from the build environment.

  • Relevant error logs:
    1:  ##[group]Operating System
    2:  Ubuntu
    ...
    
    1315:  Downloaded tree_magic_mini v3.1.4
    1316:  Downloaded opencc-rs v0.3.3
    1317:  Downloaded open v3.2.0
    1318:  Downloaded once_cell v1.19.0
    1319:  Downloaded num_cpus v1.13.1
    1320:  Downloaded num-traits v0.2.15
    1321:  Downloaded num-rational v0.4.1
    1322:  Downloaded num-integer v0.1.45
    1323:  Downloaded uuid v1.6.1
    1324:  Downloaded webkit2gtk v0.18.2
    1325:  Downloaded wayland-client v0.29.5
    1326:  Downloaded semver-parser v0.10.2
    1327:  Downloaded ryu v1.0.10
    1328:  Downloaded rfd v0.10.0
    1329:  Downloaded rand_core v0.5.1
    1330:  Downloaded proc-macro-error-attr v1.0.4
    1331:  Downloaded polling v2.5.2
    ...
    
    1335:  Downloaded nodrop v0.1.14
    1336:  Downloaded new_debug_unreachable v1.0.4
    1337:  Downloaded native-tls v0.2.10
    1338:  Downloaded lock_api v0.4.7
    1339:  Downloaded home v0.5.9
    1340:  Downloaded hex v0.4.3
    1341:  Downloaded linux-raw-sys v0.9.4
    1342:  Downloaded heck v0.4.0
    1343:  Downloaded heck v0.3.3
    1344:  Downloaded gtk3-macros v0.15.4
    1345:  Downloaded utf-8 v0.7.6
    1346:  Downloaded zbus v2.3.2
    1347:  Downloaded x11rb v0.10.1
    1348:  Downloaded tokio v1.25.0
    1349:  Downloaded rand_chacha v0.2.2
    1350:  Downloaded proc-macro-error v1.0.4
    1351:  Downloaded precomputed-hash v0.1.1
    ...
    
    1411:  Downloaded tendril v0.4.3
    1412:  Downloaded tempfile v3.20.0
    1413:  Downloaded parking_lot_core v0.9.3
    1414:  Downloaded parking_lot v0.12.1
    1415:  Downloaded memchr v2.5.0
    1416:  Downloaded itertools v0.12.1
    1417:  Downloaded toml_datetime v0.6.5
    1418:  Downloaded toml v0.8.8
    1419:  Downloaded toml v0.7.8
    1420:  Downloaded tokio-native-tls v0.3.1
    1421:  Downloaded tinyvec_macros v0.1.0
    1422:  Downloaded tinyvec v1.6.0
    1423:  Downloaded time-macros v0.2.15
    1424:  Downloaded time-core v0.1.2
    1425:  Downloaded thread_local v1.1.4
    1426:  Downloaded thiserror-impl v1.0.69
    1427:  Downloaded thiserror v1.0.69
    1428:  Downloaded tauri-winres v0.1.1
    ...
    
    1555:  Compiling serde v1.0.197
    1556:  Compiling libc v0.2.172
    1557:  Compiling pkg-config v0.3.25
    1558:  Compiling autocfg v1.1.0
    1559:  Compiling smallvec v1.8.0
    1560:  Compiling syn v1.0.95
    1561:  Compiling heck v0.4.0
    1562:  Compiling quote v1.0.35
    1563:  Compiling cfg-if v1.0.0
    1564:  Compiling syn v2.0.101
    1565:  Compiling cfg-expr v0.10.3
    1566:  Compiling version-compare v0.1.0
    1567:  Compiling memchr v2.5.0
    1568:  Compiling siphasher v0.3.10
    1569:  Compiling ppv-lite86 v0.2.16
    1570:  Compiling thiserror v1.0.69
    1571:  Compiling once_cell v1.19.0
    ...
    
    1576:  Compiling getrandom v0.2.6
    1577:  Compiling shlex v1.3.0
    1578:  Compiling lock_api v0.4.7
    1579:  Compiling parking_lot_core v0.9.3
    1580:  Compiling getrandom v0.1.16
    1581:  Compiling cc v1.2.24
    1582:  Compiling log v0.4.20
    1583:  Compiling rand_core v0.6.3
    1584:  Compiling rand_chacha v0.3.1
    1585:  Compiling rand_core v0.5.1
    1586:  Compiling rand v0.8.5
    1587:  Compiling futures-task v0.3.21
    1588:  Compiling slab v0.4.6
    1589:  Compiling rand_chacha v0.2.2
    1590:  Compiling serde_derive v1.0.197
    1591:  Compiling thiserror-impl v1.0.69
    1592:  Compiling rand_pcg v0.2.1
    1593:  Compiling futures-sink v0.3.21
    1594:  Compiling futures-util v0.3.21
    1595:  Compiling anyhow v1.0.57
    1596:  Compiling rand v0.7.3
    1597:  Compiling futures-macro v0.3.21
    1598:  Compiling phf_shared v0.10.0
    1599:  Compiling phf_shared v0.8.0
    1600:  Compiling pin-utils v0.1.0
    1601:  Compiling phf_generator v0.8.0
    1602:  Compiling phf_generator v0.10.0
    1603:  Compiling proc-macro-error-attr v1.0.4
    1604:  Compiling memoffset v0.6.5
    1605:  Compiling proc-macro-hack v0.5.19
    1606:  Compiling futures-channel v0.3.21
    1607:  Compiling proc-macro-error v1.0.4
    1608:  Compiling phf_codegen v0.10.0
    ...
    
    1695:  Compiling phf v0.8.0
    1696:  Compiling phf v0.10.1
    1697:  Compiling ctor v0.2.6
    1698:  Compiling matches v0.1.9
    1699:  Compiling itoa v0.4.8
    1700:  Compiling winnow v0.5.31
    1701:  Compiling alloc-no-stdlib v2.0.3
    1702:  Compiling hashbrown v0.12.3
    1703:  Compiling typenum v1.15.0
    1704:  Compiling stable_deref_trait v1.2.0
    1705:  Compiling nodrop v0.1.14
    1706:  Compiling adler v1.0.2
    1707:  Compiling servo_arc v0.1.1
    1708:  Compiling alloc-stdlib v0.2.1
    1709:  warning: soup2-sys@0.2.0: `PKG_CONFIG_ALLOW_SYSTEM_CFLAGS="1" "pkg-config" "--libs" "--cflags" "libsoup-2.4" "libsoup-2.4 >= 2.62"` did not exit successfully: exit status: 1
    1710:  error: failed to run custom build command for `soup2-sys v0.2.0`
    1711:  Caused by:
    ...
    
    1717:  cargo:rerun-if-env-changed=HOST_PKG_CONFIG
    1718:  cargo:rerun-if-env-changed=PKG_CONFIG
    1719:  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-gnu
    1720:  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
    1721:  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
    1722:  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
    1723:  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnu
    1724:  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu
    1725:  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
    1726:  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
    1727:  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnu
    1728:  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnu
    1729:  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
    1730:  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
    1731:  cargo:warning=`PKG_CONFIG_ALLOW_SYSTEM_CFLAGS="1" "pkg-config" "--libs" "--cflags" "libsoup-2.4" "libsoup-2.4 >= 2.62"` did not exit successfully: exit status: 1
    1732:  error: could not find system library 'libsoup-2.4' required by the 'soup2-sys' crate
    1733:  --- stderr
    1734:  Package libsoup-2.4 was not found in the pkg-config search path.
    1735:  Perhaps you should add the directory containing `libsoup-2.4.pc'
    1736:  to the PKG_CONFIG_PATH environment variable
    1737:  Package 'libsoup-2.4', required by 'virtual:world', not found
    1738:  Package 'libsoup-2.4', required by 'virtual:world', not found
    1739:  warning: build failed, waiting for other jobs to finish...
    1740:  ERROR  Error: failed to build app: failed to build app
    1741:  Error: failed to build app: failed to build app
    1742:  error Command failed with exit code 1.
    1743:  info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
    1744:  ##[error]Process completed with exit code 1.
    1745:  Post job cleanup.
    

    @dreamfliper dreamfliper merged commit 8af869a into master Jul 14, 2025
    3 of 5 checks passed
    @dreamfliper dreamfliper deleted the feat/replace-simplecc-with-opencc-rs branch July 14, 2025 02:25
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    2 participants